<?php

sys::uses("html");

class FormDrower
{
    static function draw($data)
    {
        $html = new html();

        $result = "";
        $action = isset($data["action"]) ? $data["action"] : "";
        $result .= "<form action=\"{$action}\" method=\"post\" id=\"main-container\">";
        $result .= '<div id="main-container-reducer">';
        $result .= '<div class="body-corner-tl"><span class="sys_empty4ie"></span></div>';
        $result .= '<div class="body-corner-tr"><span class="sys_empty4ie"></span></div>';
        $result .= '<div class="body-corner-br"><span class="sys_empty4ie"></span></div>';
        $result .= '<div class="body-corner-bl"><span class="sys_empty4ie"></span></div>';

        if (isset($data["header"])) {
            $result .= self::header($data["header"], $data);
        }
        if (isset($data["footer"])) {
            $result .= self::footer($data["header"], $data);
        }

        $result .= "</div>";
        $result .= "</form>";

        return $result;
    }

    static function header($data, $common_data)
    {
        $html = new html();

        $result = "";

        if (isset($common_data["serts"])) {
            $result .= self::serts($common_data["serts"], $common_data);
        }
        if (isset($common_data["caption"])) {
            $result .= "<h3>".str($common_data["caption"])->xmlEntities(ENT_NOQUOTES)->toString()."</h3>";
        }
        if (isset($data["languages"])) {
            if (count($data["languages"]["items"])) {
                $result .= "<div class=\"languages-list\">";
                $flags = array(
                    "en" => 1,
                    "de" => 2,
                    "ja" => 3,
                    "fr" => 4,
                    "pt" => 5,
                    "it" => 6,
                    "es" => 7,
                );
                foreach ($data["languages"]["items"] as $lang => $v) {
                    $attributes = array();
                    $class = "language-item";
                    if (! empty($data["languages"]["current"]) && ($data["languages"]["current"] == $lang)) {
                        $attributes["sys:inactive"] = true;
                        $class .= "-active";
                    }
                    $result .= "<span class=\"{$class}\">";
                    //$result .= $html->iconLink($v["img"], $v["caption"], $v["url"], $attributes);
                    $attributes["title"] = $v["caption"];
                    $attributes["escape"] = false;
                    $attributes["class"] = "sys_clear flag".$flags[$lang];
                    $result .= $html->link($html->image("/style/pix.gif", array("class" => "sys_clear img")), $v["url"], $attributes);
                    $result .= "</span>";
                }
                $result .= "</div>";
            }
        }

        return $result;
    }

    static function footer($data, $common_data)
    {
        $html = new html();

        $result = "";

        $cards = array(
            "visa" => 1,
            "master" => 2,
        );
        $result .= $html->image("/style/pix.gif", array("class" => "card-icon card-icon".$cards["visa"]));
        $result .= " ";
        $result .= $html->image("/style/pix.gif", array("class" => "card-icon card-icon".$cards["master"]));

        return $result;
    }

    static function serts($data, $common_data)
    {
        $html = new html();

        $result = "";

        $result .= $html->image("/style/sert_100.png");
        $result .= " ";
        $result .= $html->image("/style/sert_trust.png");
        $result .= " ";
        $result .= $html->image("/style/sert_vs.png");

        return $result;
    }
}

?>